package com.company.account.validator;

import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import com.company.account.model.AccountForms;

public class AccountValidator implements Validator {

	public boolean supports(Class clazz) {
		//just validate the Customer instances
		return AccountForms.class.isAssignableFrom(clazz);

	}

	public void validate(Object target, Errors errors) {
		
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "numero",
			"required.numero", "El campo es necesario.");
		

		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "balance",
				"required.balance", "El campo es necesario.");
		
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "nombre",
				"required.nombre", "El campo es necesario.");
		
		AccountForms obj = (AccountForms)target;
		
		if("NONE".equals(obj.getEstado())) {
			errors.rejectValue("estado", "required.estado");
		}
	}

}
